package com.woniuxy.consumer;

import com.woniuxy.config.RedisConfig;
import com.woniuxy.domain.Orderr;
import com.woniuxy.service.OrderService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.RocketMQTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(consumerGroup = "woniu_order",topic = "order")
@RocketMQTransactionListener()
public class OrderConsumer implements RocketMQListener<Orderr> {
    @Autowired
    private RedisConfig redisConfig;
    @Autowired
    private OrderService orderService;
    @Override
    public void onMessage(Orderr orderr) {
        System.out.println(orderr.getoId());
        System.out.println(redisConfig.opsForHash().hasKey("OrderRocket", orderr.getoId()));
        if(!redisConfig.opsForHash().hasKey("OrderRocket", orderr.getoId())){
            orderr.setoStatus("1");
            orderService.updateById(orderr);
        }

    }
}
